﻿
Partial Class WebForm_MySlidingMenuGroup
    Inherits System.Web.UI.UserControl

    Protected Sub rep_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rep.ItemCommand
        If e.CommandName = "lknMenuName" Then
            'Me.SelectedMenuName = TryCast(e.CommandSource, LinkButton).Text
            'Response.Redirect("~\WebForm\" + e.CommandArgument)
            'Response.Redirect(String.Format("~\{0}\{1}", Me.ProgramDirectory, e.CommandArgument))
            Response.Redirect(e.CommandArgument)
        End If
    End Sub

    Protected Sub rep_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rep.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            'Response.Write(Me.SelectedMenuName + TryCast(e.Item.FindControl("lknMenuName"), LinkButton).Text + "<br>")
            'If Me.SelectedMenuName = TryCast(e.Item.FindControl("lknMenuName"), LinkButton).Text Then

            'If TryCast(e.Item.FindControl("lknMenuName"), LinkButton).CommandArgument = Request.RawUrl.Split("/")(Request.RawUrl.Split("/").Length - 1) Then
            If DataBinder.Eval(e.Item.DataItem, "ProgramID") = Request("ProgramID") Then
                ''TryCast(e.Item.FindControl("lknMenuName"), LinkButton).BorderColor = System.Drawing.Color.Red
                TryCast(e.Item.FindControl("lknMenuName"), LinkButton).Attributes.Add("style", "color:Red;font-size: 14px")
                Me.Collapsed = False
            Else
                TryCast(e.Item.FindControl("lknMenuName"), LinkButton).Attributes.Add("style", "color:Blue;font-size: 14px")
                'TryCast(e.Item.FindControl("lknMenuName"), LinkButton).BorderColor = System.Drawing.Color.Blue
            End If

            Dim url As String = String.Format("~\{0}\{1}?ProgramID={2}", Me.ProgramDirectory, DataBinder.Eval(e.Item.DataItem, "Url"), DataBinder.Eval(e.Item.DataItem, "ProgramID"))
            TryCast(e.Item.FindControl("lknMenuName"), LinkButton).CommandArgument = Me.ResolveUrl(url)
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.cpeDemo.Collapsed = Me.Collapsed
            Me.cpeDemo.ClientState = Me.Collapsed.ToString()

            'Response.Write(Convert.ChangeType(Me.cpeDemo.ClientState, TypeCode.Boolean))
        Else
            'Response.Write(Convert.ChangeType(Me.cpeDemo.ClientState, TypeCode.Boolean))
            'Response.Write(Me.cpeDemo.Collapsed)
            Me.Collapsed = Convert.ChangeType(Me.cpeDemo.ClientState, TypeCode.Boolean)

            'Response.Write(Me.Collapsed)
        End If
    End Sub
End Class

Partial Class WebForm_MySlidingMenuGroup
    Public Sub BindGV(ByVal dt As Data.DataTable)
        Me.rep.DataSource = dt
        Me.rep.DataBind()


    End Sub

    Public Property ProgramID() As String
        Get
            Return ViewState("ProgramID")
        End Get
        Set(ByVal value As String)
            ViewState("ProgramID") = value
        End Set
    End Property

    Public Property MenuName() As String
        Get
            Return Me.lblMenuName.Text
        End Get
        Set(ByVal value As String)
            Me.lblMenuName.Text = value
        End Set
    End Property

    Public Property ProgramDirectory() As String
        Get
            If ViewState("ProgramDirectory") Is Nothing Then
                Return "WebForm"
            End If

            Return ViewState("ProgramDirectory")
        End Get
        Set(ByVal value As String)
            ViewState("ProgramDirectory") = value
        End Set
    End Property

    'Private Property SelectedMenuName() As String
    '    Get
    '        Return Session("SelectedMenuName")
    '    End Get
    '    Set(ByVal value As String)
    '        Session("SelectedMenuName") = value
    '    End Set
    'End Property

    Private Property Collapsed() As Boolean
        Get
            If Session(Me.UniqueID + "Collapsed") Is Nothing Then
                Return False
            End If

            Return Session(Me.UniqueID + "Collapsed")
        End Get
        Set(ByVal value As Boolean)
            Session(Me.UniqueID + "Collapsed") = value
        End Set
    End Property
End Class